class Solution(object):
    def firstBadVersion(self, n):
        """
        :type n: int
        :rtype: int
        """
        l = 0
        h = n
        while l < h:
            m = l + (h - l) / 2

            if not isBadVersion(m):
                l = m + 1
            else:
                h = m
        return l
